package com.ftwj.demo.config.task;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import com.ftwj.demo.utils.logs.LoggerUtil;

/**
*
* <p>Title: SchedulingConfig</p>  
* <p>Description: 为Spring Task配置线程池</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* <p>Company: 兰州飞天网景信息产业有限公司</p>    
* @author WangSLi
* @date 2020年2月29日 上午11:37:17
* @version V1.0
 */
@Configuration
public class SchedulingConfig { // implements SchedulingConfigurer
	
	private ThreadPoolTaskScheduler taskScheduler;
	
    @Bean
    public TaskScheduler taskScheduler() {
    	LoggerUtil.info("初始化线程池...");
    	taskScheduler = new ThreadPoolTaskScheduler();
        // 定时任务执行线程池核心线程数
        taskScheduler.setPoolSize(16);
        taskScheduler.setRemoveOnCancelPolicy(true);
        taskScheduler.setThreadNamePrefix("TaskSchedulerThreadPool-");
        return taskScheduler;
    }
    
    public int getActiveCount() {
    	return taskScheduler!=null?taskScheduler.getActiveCount():0;
    }
    
    public int getPoolSize() {
    	return taskScheduler!=null?taskScheduler.getPoolSize():0;
    }
}